<template>
  <basic-container>
    <avue-crud :option="option"
      :search.sync="search"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad">
      <template slot-scope="{ row }" slot="betweenDay">
        <div v-if="row.betweenDay">
          <span>{{ row.betweenDay === '0'?'24小时内':row.betweenDay+'天' }}</span>
        </div>
      </template>
      <template slot-scope="{}" slot="serviceNoSearch">
        <select-page ref="searchSerSelect" label="serviceName" value="serviceNo" :select.sync="search.serviceNo" :url="website.searchLink.serviceUrl" placeholder-text="代理商编号" filter-key="searchParam"></select-page>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
import {getList} from "@/api/rb-oem/serviceLoginInfo/serviceLoginInfo";
import {mapGetters} from "vuex";
import selectPage from "@/components/select-page/select-page";

export default {
  components: {
    selectPage
  },
  data() {
    return {
      form: {},
      query: {},
      search: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      selectionList: [],
      option: {
        height:'auto',
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        viewBtn: true,
        addBtn:false,
        editBtn:false,
        delBtn:false,
        selection: false,
        searchMenuSpan: 6,
        columnBtn: false,
        labelWidth:120,
        searchLabelWidth:120,
        column: [
          {
            label: "代理商编号",
            prop: "serviceNo",
            type: "input",
            search:true
  				},
          {
            label: "上次登录大于多少天",
            prop: "loginDay",
            type: "number",
            search: true,
            hide: true,
            display: false,
            controls: false,
  				},
          {
            label: "代理商名称",
            prop: "serviceName",
            type: "input"
  				},
          {
            label: "最后登录时间",
            prop: "lastTime",
            type: "input"
  				},
          {
            label: "上次登录",
            prop: "betweenDay",
            type: "input"
  				}
        ]
      },
      data: []
    };
  },
  computed: {
    ...mapGetters(["permission"]),
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
    }
  },
  methods: {
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        // getDetail(this.form.id).then(res => {
        //   this.form = res.data.data;
        // });
      }
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage){
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize){
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    }
  }
};
</script>

<style>
</style>
